#define _CRT_SECURE_NO_WARNINGS 1
#include<stdio.h>
int main()
{
    int N = 0;
    scanf("%d", &N);
    int arr[1000] = { 0 };
    int i = 0;
    for (i = 0; i < N; i++)
    {
        arr[i] = 1;
    }
    int count = 0, n = 0, t = 0, sign = 0;
    i = 0;
    while (t != 1)
    {
        if (N == 1)
        {
            break;
        }
        for (i = 0; i < N; i++)
        {
            if (arr[i] == 1)
            {
                count++;
                if (count % 3 == 0)
                {
                    arr[i] = 0;
                    n++;
                    t = N - n;
                }
            }
        }
        if (count % 3 == 0)
        {
            count = 0;
        }
        else if (count % 3 == 1)
        {
            count = 1;
        }
        else if (count % 3 == 2)
        {
            count = 2;
        }
    }
    i = 0;
    for (i = 0; i < N; i++)
    {
        if (arr[i] != 0)
        {
            sign = i + 1;
            break;
        }
    }
    printf("%d", sign);
    return 0;
}
